package name.vaccari.matteo.tai.phonedirectory.web;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import name.vaccari.matteo.tai.phonedirectory.model.PeopleRepository;
import name.vaccari.matteo.tai.phonedirectory.model.Person;
import name.vaccari.matteo.tai.phonedirectory.persistence.InMemoryPeopleRepository;

import org.junit.Test;


public class PeopleServletTest {

	private final class EmptyRepository implements
			PeopleRepository {
		public List<Person> getPeople(int startIndex, int howMany) {
			return Collections.emptyList();
		}

		public int getTotalPeople() {
			return 0;
		}
	}

	@Test
	public void testname() throws Exception {
		PeopleServlet servlet = new PeopleServlet(new EmptyRepository());
		String body = servlet.doGet("/");
		
		String heading = "<h1>People Directory</h1>";		
		String tableStart = "<table>";
		String rows = "";
		String tableEnd = "</table>";
		String expectedBody = heading  + tableStart  + rows + tableEnd ;
		
		assertEquals(expectedBody, body);
	}
	
	@Test
	public void testOneRow() throws Exception {
		Person person = new Person();
		person.setFirstName("Gino");
		person.setLastName("Rossi");
		person.setMobile("0123456");
		
		PeopleServlet servlet = new PeopleServlet(new EmptyRepository());
		String row = servlet.convertPersonToTableRow(person);
		assertEquals("<tr><td>Rossi</td><td>Gino</td><td>0123456</td></tr>", row);
	}
}
